<template>
  <Layout>
    <Form ref="form1" :model="form1" :label-width="120">
      <Row class="query-form" style="padding-top: 15px">
        <Col span="8">
          <FormItem label="企业名称：">
            <cascaderDom ref="childOrg" @setOrgInfo="setOrgId" @setOrgname="setOrgName"
                         :orgTree="true" :root-org-id="companyId"></cascaderDom>
          </FormItem>
        </Col>
        <Col span="8">
          <FormItem label="年份：">
            <DatePicker type="year" v-model="form1.yearDate" style="width: 100%"></DatePicker>
          </FormItem>
        </Col>
        <Col span="8">
          <Button @click="reset" class="ivu-btn-reset">重置</Button>
          <Button class="ivu-btn-query" icon="md-search" @click="query()">查询</Button>
        </Col>
      </Row>
    </Form>
    <Table ref='table' :loading="loading" size="small" :height="tableHeight" class="no-add-table"
           no-data-text="没有查询到相关数据!"
           highlight-row stripe border :columns="columns1" width="100%" :data="dataTable">
    </Table>

  </Layout>
</template>

<script>
import {Api} from '../../../api/index.js'
import {sessionStorage} from '../../../common/cacheUtils.js';
import cascaderDom from '../../../components/cascader-dom.vue';

export default {
  components: {cascaderDom},
  name: "riskStatical",
  data() {
    return {
      loading: false, tableHeight: '',
      form1: {
        orgId: '',
        year: '',
        yearDate: ''
      },
      pageSizeArray: [10, 20, 50],
      pagedata: {
        total: 0,
        pageSize: 10,
        currentPage: 1,
      },
      companyId: sessionStorage('userId').getObject('userId').companyId,
      dataTable: [],
      columns1: [
        {
          title: "序号",
          width: 80,
          align: "center",
          fixed: 'left',
          render: (h, params) => {
            if (params.row.id === '-1') return h('span', "汇总");
            return h('span', params.index + 1);
          }
        },
        {
          minWidth: 200,
          title: '单位名称',
          align: 'center',
          fixed: 'left',
          key: 'contractorName',
        },
        {
          minWidth: 320,
          title: '风险总数',
          align: 'center',
          children: [
            {
              title: '重大',
              key: 'account1',
              align: 'center',
              width: 80
            }, {
              title: '较大',
              key: 'account2',
              align: 'center',
              width: 80
            }, {
              title: '一般',
              key: 'account3',
              align: 'center',
              width: 80
            }, {
              title: '低',
              key: 'account4',
              align: 'center',
              width: 80
            },
            {
              title: '合计',
              key: 'accountTotal',
              align: 'center',
              width: 80
            },
          ]
        },
        {
          minWidth: 150,
          title: '设备设施风险',
          align: 'center',
          children: [
            {
              title: '重大',
              key: 'equipmentAccount1',
              align: 'center',
              width: 80
            }, {
              title: '较大',
              key: 'equipmentAccount2',
              align: 'center',
              width: 80
            }, {
              title: '一般',
              key: 'equipmentAccount3',
              align: 'center',
              width: 80
            }, {
              title: '低',
              key: 'equipmentAccount4',
              align: 'center',
              width: 80
            },
            {
              title: '合计',
              key: 'equipmentAccountTotal',
              align: 'center',
              width: 80
            },
          ]
        },
        {
          minWidth: 150,
          title: '作业流程风险',
          align: 'center',
          children: [
            {
              title: '重大',
              key: 'workAccount1',
              align: 'center',
              width: 80
            }, {
              title: '较大',
              key: 'workAccount2',
              align: 'center',
              width: 80
            }, {
              title: '一般',
              key: 'workAccount3',
              align: 'center',
              width: 80
            }, {
              title: '低',
              key: 'workAccount4',
              align: 'center',
              width: 80
            },
            {
              title: '合计',
              key: 'workAccountTotal',
              align: 'center',
              width: 80
            },
          ]
        },
        {
          minWidth: 150,
          title: '人员岗位风险',
          align: 'center',
          children: [
            {
              title: '重大',
              key: 'personAccount1',
              align: 'center',
              width: 80
            }, {
              title: '较大',
              key: 'personAccount2',
              align: 'center',
              width: 80
            }, {
              title: '一般',
              key: 'personAccount3',
              align: 'center',
              width: 80
            }, {
              title: '低',
              key: 'personAccount4',
              align: 'center',
              width: 80
            },
            {
              title: '合计',
              key: 'personAccountTotal',
              align: 'center',
              width: 80
            },
          ]
        }, {
          minWidth: 150,
          title: '环境氛围风险',
          align: 'center',
          children: [
            {
              title: '重大',
              key: 'environmentalAccount1',
              align: 'center',
              width: 80
            }, {
              title: '较大',
              key: 'environmentalAccount2',
              align: 'center',
              width: 80
            }, {
              title: '一般',
              key: 'environmentalAccount3',
              align: 'center',
              width: 80
            }, {
              title: '低',
              key: 'environmentalAccount4',
              align: 'center',
              width: 80
            },
            {
              title: '合计',
              key: 'environmentalAccountTotal',
              align: 'center',
              width: 80
            },
          ]
        },
        /*{
            title: '操作',
            key: 'action',
            fixed: 'right',
            width: 140,
            align: 'center',
            render: (h, params) => {
                return h('div', [
                    h('A', {
                        props: {
                            type: 'primary',
                            size: 'small'
                        },
                        style: {
                            fontSize: '12px',
                        },
                        on: {
                            click: () => {
                                this.InputData = params.row;
                                this.model2 = true;
                            }
                        }
                    }, '详情'),
                    h('A', {
                        props: {
                            type: 'primary',
                            size: 'small'
                        },
                        style: {
                            fontSize: '12px',
                            marginLeft: '8px'
                        },
                        on: {
                            click: () => {
                                this.InputData = params.row;
                                this.model1 = true;
                            }
                        }
                    }, '修改'),
                    h('A', {
                        props: {
                            type: 'error',
                            size: 'small'
                        },
                        style: {
                            fontSize: '12px',
                            color: 'red',
                            marginLeft: '8px'
                        },
                        on: {
                            click: () => {
                                this.deleteData(params.row);
                            }
                        }
                    }, '删除')
                ]);
            }
        }*/
      ],
      model1: false,
      model2: false,
      buttonDisabled: false,
      InputData: {},
    }
  },
  mounted() {
    this.tableHeight = window.innerHeight - this.$refs.table.$el.offsetTop - 145;
    this.query()

  },
  methods: {


    setOrgId(data) {
      this.form1.orgId = data[data.length - 1];
    },
    setOrgName(data) {
      this.form1.orgName = data;
    },
    query() {
      this.loading = true;


      let data = {
        startPage: this.pagedata.currentPage,
        size: this.pagedata.pageSize,

      };
      let user = sessionStorage('userId').getObject('userId');
      if (this.form1.orgId == "") {
        this.form1.orgId = user.companyName
      }
      if (this.form1.year) {
        this.form1.year = new Date(this.form1.yearDate).getFullYear()
      } else {
        this.form1.yearDate = new Date()
        this.form1.year = new Date().getFullYear();
      }

      data = Object.assign(data, JSON.parse(JSON.stringify(this.form1)));
      let url = Api.riskStaticalList
      this.$http.get(url, {params: data}).then((res) => {
        this.dataTable = res.data.data.data;
        // this.pagedata.total = res.data.data.totalSize;
        this.loading = false;
      }).catch(e => {
        this.$Message.error("数据获取失败")
      })
    },
    reset() {
      this.form1 = {
        orgId: '',
        year: '',
      }
      this.$refs.childOrg.resetCurrentOrg();
      this.query();
    },
    pageChange(pageNum) {
      this.pagedata.currentPage = pageNum;
      this.query();
    },
    pageSizeChange(pageSize) {
      this.pagedata.pageSize = pageSize;
      this.query();
    },
  }
}
</script>

<style scoped>
@import '../../../index.css';
</style>
